package cn.school.sys.dao;

import cn.school.sys.entity.SysUser;
import cn.school.sys.vo.LoginInfoVo;
import cn.school.teacher.evaluation.dto.UserDto;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 后台用户表
 */
@Mapper
public interface SysUserDao extends BaseMapper<SysUser> {
    List<SysUser> getClassTeacherList(@Param("tenantId") String tenantId);

    List<SysUser> getTeacherList(@Param("tenantId") String tenantId);

    List<SysUser> getDorTeacherList();

    //APP端用户登录接口
    SysUser doLogin(@Param("username")String username);

    String getLoginPassword(@Param("id")int id);

    int updatePassword(@Param("id") int id ,@Param("newPassword") String newPassword);

    int getRoleCount(@Param("id")int id);

    int getRoleTeaCount(@Param("id")int id);

    LoginInfoVo getLoginInfo(@Param("username")String username);

    /**
     * 根据部门名称查询部门领导人
     * @param deptName
     * @return
     */
    List<String> findDeptLeaderApprovalUserByDeptName(@Param("deptName")String deptName);

    /**
     * 查询班主任用户
     * */
    List<UserDto> getClassTeacherListBySearch(IPage<UserDto> page,  @Param("ew") QueryWrapper<UserDto> wrapper);

    List<UserDto> getClassTeacherListBySearchAndName(IPage<UserDto> page,  @Param("ew") QueryWrapper<UserDto> wrapper, @Param("name") String name);

    /**
     * 查询教职工用户
     * */
    List<UserDto> getEmployeListBySearch(IPage<UserDto> page,  @Param("ew") QueryWrapper<UserDto> wrapper);

    List<UserDto> getEmployeListBySearchAndName(IPage<UserDto> page,  @Param("ew") QueryWrapper<UserDto> wrapper, @Param("name") String name);

    /**
     * 人员管理（班主任、教师，分页列表获取数据）
     * */
    @Select(value = "" +
            "select\n" +
            "   distinct" +
//            "   syro.name,"+
            "   syus.id," +
            "   syus.username, syus.dept_id, syus.dept_name, syus.email, syus.phone,\n" +
            "   syus.sex, syus.icon, syus.note, syus.`status`, syus.login_time, \n" +
            "   syus.login_ip, syus.is_dept_leader, syus.create_time, syus.modify_time, syus.sysu_name,\n" +
            "   syus.sysu_card_no, syus.sysu_education, syus.sysu_academic_degree,  syus.sysu_graduation_school, syus.sysu_working_years,\n" +
            "   syus.sysu_hiredate, syus.sysu_leavedate\n" +
            "from " +
            "   t_sys_user syus left join t_sys_dept syde on (\n" +
            "       syus.dept_id = syde.id\n" +
            "   ) left join t_sys_user_role suro on (\n" +
            "       syus.id = suro.user_id\n" +
            "   ) left join t_sys_role syro on (\n" +
            "       suro.role_id = syro.id\n" +
            "   )\n" +
            "\n" +
            "${ew.customSqlSegment}")
    List<SysUser> getPage(Page page, @Param("ew") QueryWrapper<SysUser> wrapper);

    /**
     * 根据租户id批量更新用户状态
     * @Param:
     * @return:
     * @Author: lx
     * @date: 2023/4/24
     */
    void updateStatusBatchByTenantId(@Param("tenantId")Long tenantId,@Param("status")String status);

    List<String> getTeacherOpenIdList(List<String> teacherNames);

    List<SysUser> userPhoneList(@Param("user") SysUser user, @Param("startNum") Integer startNum, @Param("endNum")Integer endNum);

    int userPhoneListCount(@Param("user") SysUser user);

    List<String> getSysUserNamesByRoleName(@Param("tenantId") String tenantId, @Param("roleName") String ruleName);
}
